﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace Wjtour.BLL
{
    public class picturetype_bll : base_dll
    {
        public Wjtour.Domain.picturetype Load(int id)
        {
            string sql = "select * from picturetype where parenttypeid=" + id;
            return DbAccess.GetObjects<Wjtour.Domain.picturetype>(sql).FirstOrDefault();
        }

        public bool Save(Wjtour.Domain.picturetype entity)
        {
            string sql = "";

            DbCommand cmd = DbAccess.CreateCommand();

            if (entity.id > 0)
            {
                sql = @"UPDATE [picturetype] SET 
                [picturetypename] = @picturetypename,
                [parenttypeid] = @parenttypeid,
                [idpath] = @idpath,
                [namepath] = @namepath,
                [layer] = @layer,
                [isactive] = @isactive,
                [tag] = @tag
                 WHERE id=@id";
                DbAccess.AddInParameter(cmd, "@id", DbType.Int32, entity.id);

            }
            else
            {
                sql = @"INSERT INTO [picturetype]( 
                [picturetypename],[parenttypeid],[idpath],[namepath],[layer],[isactive],[tag])VALUES(
                @picturetypename,@parenttypeid,@idpath,@namepath,@layer,@isactive,@tag)";
            }
            DbAccess.AddInParameter(cmd, "@picturetypename", DbType.String, entity.picturetypename);
            DbAccess.AddInParameter(cmd, "@parenttypeid", DbType.Int32, entity.parenttypeid);
            DbAccess.AddInParameter(cmd, "@idpath", DbType.String, entity.idpath);
            DbAccess.AddInParameter(cmd, "@namepath", DbType.String, entity.namepath);
            DbAccess.AddInParameter(cmd, "@layer", DbType.Int32, entity.layer);
            DbAccess.AddInParameter(cmd, "@isactive", DbType.Int32, entity.isactive);
            DbAccess.AddInParameter(cmd, "@tag", DbType.String, entity.tag);
            cmd.CommandText = sql;
            cmd.CommandType = System.Data.CommandType.Text;
            return DbAccess.ExecuteNonQuery(cmd) > 0;

        }


        public int BatchDelete(string ids)
        {
            string sql = "delete from picturetype where id in(" + ids + ")";
            return DbAccess.ExecuteNonQuery(sql);
        }
    }
}
